package com.walnut.service;

import com.walnut.dao.ImmortalDAO;
import com.walnut.model.Immortal;
import com.walnut.utils.Utils;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by parker on 15/4/5.
 */
public class ImmortalManagerImpl implements ImmortalManager{
    /**
     * Immortal dao injected by Spring context
     */
    private ImmortalDAO immortalDAO;
    /**
     * create a new immortal.This method will be called when a immortal object is added
     *
     * @param immortal the candidate
     */
    @Override
    @Transactional
    public void addImmortal(Immortal immortal) {
        immortalDAO.addImmortal(immortal);
    }

    /**
     * delete the specific immortal.
     *
     * @param immortalId the unique identity of the specific immortal
     */
    @Override
    @Transactional
    public void deleteImmortal(Integer immortalId) {
        immortalDAO.deleteImmortal(immortalId);
    }

    /**
     * retrieve the all immortals
     *
     * @return
     */
    @Override
    @Transactional
    public List<Immortal> getAllImmortals() {
        return immortalDAO.getAllImmortals();
    }

    /**
     * retrieve the detail info of the specific immortal
     *
     * @param immortalId
     * @return
     */
    @Override
    @Transactional
    public Immortal getImmortal(Integer immortalId) {
        return immortalDAO.getImmortal(immortalId);
    }

    /**
     * retrieve the part of detail info of the specific immortal
     *
     * @param id             the unique identity of the specific immortal
     * @param selectedFields the selected fields which will be used by developers
     * @return the specific immortal
     */
    @Override
    @Transactional
    public Immortal getImmortal(Integer id, String selectedFields) {
        Immortal immortal = immortalDAO.getImmortal(id, selectedFields);
        return immortal;
    }

    public void setImmortalDAO(ImmortalDAO dao){
        this.immortalDAO = dao;
    }
}
